<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>综合计算工具</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
</head>

<body>
    <div class="container mt-5">
        <h1 class="mb-4">综合计算工具</h1>
        <form onsubmit="return false;">
            <div class="form-group">
                <label for="inputText">请输入要计算的数字，用逗号分隔：</label>
                <textarea class="form-control" id="inputText" rows="3"></textarea>
            </div>
            <button type="button" class="btn btn-primary" onclick="calculate()">计算</button>
        </form>
        <div class="mt-4">
            <p>计算结果：</p>
            <div class="row">
                <div class="col">
                    <div class="form-group">
                        <label for="count">数量：</label>
                        <input type="text" class="form-control" id="count" readonly>
                    </div>
                    <div class="form-group">
                        <label for="average">算数平均值：</label>
                        <input type="text" class="form-control" id="average" readonly>
                    </div>
                    <div class="form-group">
                        <label for="geometric">几何平均值：</label>
                        <input type="text" class="form-control" id="geometric" readonly>
                    </div>
                    <div class="form-group">
                        <label for="median">中位数：</label>
                        <input type="text" class="form-control" id="median" readonly>
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <label for="max">最大值：</label>
                        <input type="text" class="form-control" id="max" readonly>
                    </div>
                    <div class="form-group">
                        <label for="min">最小值：</label>
                        <input type="text" class="form-control" id="min" readonly>
                    </div>
                    <div class="form-group">
                        <label for="addition">相加结果：</label>
                        <input type="text" class="form-control" id="addition" readonly>
                    </div>
                    <div class="form-group">
                        <label for="multiplication">相乘结果：</label>
                        <input type="text" class="form-control" id="multiplication" readonly>
                    </div>
                </div>
                <div class="col">
                    <div class="form-group">
                        <label for="sampleStandardDeviation">样本标准差：</label>
                        <input type="text" class="form-control" id="sampleStandardDeviation" readonly>
                    </div>
                    <div class="form-group">
                        <label for="sampleVariance">样本标准差的方差：</label>
                        <input type="text" class="form-control" id="sampleVariance" readonly>
                    </div>
                    <div class="form-group">
                        <label for="populationStandardDeviation">总体标准差：</label>
                        <input type="text" class="form-control" id="populationStandardDeviation" readonly>
                    </div>
                    <div class="form-group">
                        <label for="populationVariance">总体标准差的方差：</label>
                        <input type="text" class="form-control" id="populationVariance" readonly>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        function calculate() {
            const inputText = document.getElementById("inputText").value;
            const numbers = inputText.split(",").map(parseFloat);

            if (!numbers.every(Number.isFinite)) {
                alert("请输入有效数值！");
                return;
            }

            const count = numbers.length;
            const sum = numbers.reduce((acc, cur) => acc + cur, 0);
            const average = sum / count;
            const geometric = Math.pow(numbers.reduce((acc, cur) => acc * cur, 1), 1 / count);
            const sorted = [...numbers].sort((a, b) => a - b);
            const median = count % 2 === 0 ? (sorted[count / 2 - 1] + sorted[count / 2]) / 2 : sorted[(count - 1) / 2];
            const max = Math.max(...numbers);
            const min = Math.min(...numbers);
            const addition = numbers.reduce((acc, cur) => acc + cur, 0);
            const subtraction = numbers.slice(1).reduce((acc, cur) => acc - cur, numbers[0]);
            const multiplication = numbers.reduce((acc, cur) => acc * cur, 1);
            const sampleStandardDeviation = Math.sqrt(numbers.reduce((acc, cur) => acc + Math.pow(cur - average, 2), 0) / (count - 1));
            const sampleVariance = numbers.reduce((acc, cur) => acc + Math.pow(cur - average, 2), 0) / (count - 1);
            const populationStandardDeviation = Math.sqrt(numbers.reduce((acc, cur) => acc + Math.pow(cur - average, 2), 0) / count);
            const populationVariance = numbers.reduce((acc, cur) => acc + Math.pow(cur - average, 2), 0) / count;

            document.getElementById("count").value = count;
            document.getElementById("average").value = average.toFixed(5);
            document.getElementById("geometric").value = geometric.toFixed(5);
            document.getElementById("median").value = median;
            document.getElementById("max").value = max;
            document.getElementById("min").value = min;
            document.getElementById("addition").value = addition;
            document.getElementById("subtraction").value = subtraction;
            document.getElementById("multiplication").value = multiplication;
            document.getElementById("sampleStandardDeviation").value = sampleStandardDeviation.toFixed(5);
            document.getElementById("sampleVariance").value = sampleVariance.toFixed(5);
            document.getElementById("populationStandardDeviation").value = populationStandardDeviation.toFixed(5);
            document.getElementById("populationVariance").value = populationVariance.toFixed(5);
        }
    </script>
</body>

</html>